package com.bianyuanren.web.controller.app;


import com.bianyuanren.common.annotation.Log;
import com.bianyuanren.common.core.controller.BaseController;
import com.bianyuanren.common.core.domain.AjaxResult;
import com.bianyuanren.common.core.page.TableDataInfo;
import com.bianyuanren.common.enums.BusinessType;
import com.bianyuanren.v4.pojo.files.PpFiles;
import com.bianyuanren.v4.service.files.IPpFilesService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 文件Controller
 * 
 * @author pengpeng
 * @date 2020-06-05
 */
@Controller
@RequestMapping("/app/files")
public class AppFilesController extends BaseController
{
    private String prefix = "app/files";

    @Autowired
    private IPpFilesService ppFilesService;

    @RequiresPermissions("system:files:view")
    @GetMapping()
    public String files()
    {
        return prefix + "/files";
    }

    /**
     * 查询文件列表
     */
    @RequiresPermissions("system:files:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PpFiles ppFiles)
    {
        startPage();
        List<PpFiles> list = ppFilesService.userImages(ppFiles);
        return getDataTable(list);
    }

    /**
     * 删除文件
     */
    @RequiresPermissions("system:files:remove")
    @Log(title = "文件", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ppFilesService.deletePpFilesByIds(ids));
    }
}
